package my.design.template.handler;

import cn.hutool.core.util.RandomUtil;

import java.math.BigDecimal;
import java.util.function.Consumer;

/**
 * @author zp
 * @version 1.0
 * @description: 函数式编程方式实现模板模式
 * @date 2022/10/18 19:36
 */
public class BankBusinessHandlerCustomer {
    /**
     * @description: 存钱
     * @author zp
     * @date: 2022/11/13 15:52
     * @param amount
     */
    public void save(BigDecimal amount) {
        execute(a -> System.out.println("存钱：" + amount));
    }

    /**
     * @description: 理财
     * @author zp
     * @date: 2022/11/13 15:52
     * @param amount
     */
    public void draw(BigDecimal amount) {
        execute(a -> System.out.println("理财：" + amount));
    }

    /**
     * @description:  模板方法，执行器
     * @author zp
     * @date: 2022/11/13 15:52
     * @param consumer
     */
    public void execute(Consumer<BigDecimal> consumer) {
        getNumber();
        consumer.accept(null);
        judge();
    }

    /**
     * @description:  取号
     * @author zp
     * @date: 2022/11/13 15:53
     */
    private void getNumber() {
        System.out.println("取号：" + RandomUtil.randomNumbers(8));
    }

    /**
     * @description:  评价
     * @author zp
     * @date: 2022/11/13 15:53
     */
    private void judge() {
        System.out.println("评价：五星好评！");
    }
}
